<tr>
	<td colspan="6" style="padding:0px;">
	<#if child_list??>
	<#assign selectedIds="">
	<#assign colCount=0>
	<table id="listForSelect_${field.id}" width="100%" cellspacing=0 cellpadding=0>
		<tr class="listviewHeader">
			<#if child_list.listFields?? && child_list.listFields?size gt 0>
			<#list child_list.listFields as listField>
			<#if listField.field?? && (!listField.isHidden?? || listField.isHidden=='0')>
			<td align="${listField.align?default('center')}" width="${listField.width?default(100)}">
				${listField.title?default('')}
				<#assign colCount = colCount + 1>
			</td>
			</#if>
			</#list>
			</#if>
			<!-- 只读时不显示操作列 -->
			<#if formField.readonly?default('0')!="1">
			<td align="center" width="30">
				操作
			</td>
			</#if>
		</tr>
		<#if child_instance_list?? && child_instance_list?size gt 0>
		<#list child_instance_list as instance>
		<tr id="${field.id}_${instance.fieldMap['id'].value}">
			<#list child_list.listFields as listField>
				<#if listField.field?? && (!listField.isHidden?? || listField.isHidden=='0')>
				<td align="${listField.align?default('center')}" class="listviewContent">				
					<#if instance.fieldMap?? && instance.fieldMap[listField.field.name]??>
						<#if instance.fieldMap[listField.field.name].displayValue??>
							${instance.fieldMap[listField.field.name].displayValue}
						<#else>
							${instance.fieldMap[listField.field.name].value?default('')}
						</#if>
					</#if>
				</td>
				</#if>
			</#list>
			<!-- 只读时不显示操作列 -->
			<#if formField.readonly?default('0')!="1">
			<td align="center" class="listviewContent" >
				<a href="javascript:void(0);" onclick="removeSelection${field.id}('${field.id}_${instance.fieldMap['id'].value}');return false;">移除</a>
			</td>
			</#if>
		</tr>
		<#assign selectedIds = selectedIds + instance.fieldMap['id'].value + ','>
		</#list>
		</#if>
		<#if formField.readonly?default('0')!="1">
		<tr>
			<td colspan="${colCount+1}" class="listviewContent">
				<a href="#" class="button" tabindex="-1">
					<input type="button" onclick="showMenu${field.id}();" value="选择${field.displayName}"/>
				</a>
			</td>
		</tr>
		</#if>
	</table>
	
	<input type=hidden name="fieldMap['${field.name}Ids'].id"></input>
	<input type=hidden name="fieldMap['${field.name}Ids'].field.id" value="${field.id}"></input>
	<input type=hidden id="selectedIds_${field.id}" name="fieldMap['${field.name}Ids'].value" value="${selectedIds}"></input>
			
	<script>
	function showMenu${field.id}(){
		new Win({
			url:TDQS.CONTEXT_PATH+"${action}?selectedIds="+$('#selectedIds_${field.id}').val()+'&saveFunction=save${field.id}&excludePlanItem=1',
			title:"${field.displayName}",
			width:${width?default(550)},
			height:320,
			center:true,
			resizable:false
		});
	}
	
	function save${field.id}(rowData){
		for (var i=0;i<rowData.length;i++) {
			var rec = rowData[i];
			var tr = '<tr id="${field.id}_'+rec.id+'">';
			<#list child_list.listFields as listField>
			<#if listField.field?? && (!listField.isHidden?? || listField.isHidden=='0')>
				tr += '<td align="${listField.align?default('center')}" class="listviewContent">';
				tr += rec.${listField.field.name} == null ? '&nbsp;' : rec.${listField.field.name};
				tr += '</td>';
			</#if>
			</#list>
			
			//只读时不显示操作列
			<#if formField.readonly?default('0')!="1">
			tr += '<td align="center" class="listviewContent" >';
			tr += '<a href="javascript:void(0);" onclick="javascript:removeSelection${field.id}(\'${field.id}_'+rec.id+'\');return false;">移除</a>';
			tr += '</td>';
			</#if>
			tr += '</tr>';
			
			var trArray = $('tr',document.getElementById('listForSelect_${field.id}'));
			$(tr).insertAfter($(trArray[trArray.length-2]));
			
			var selectedIds = $('#selectedIds_${field.id}').val();
			if (selectedIds.indexOf(rec.id) == -1){
				selectedIds += rec.id + ',';
				$('#selectedIds_${field.id}').val(selectedIds);
			}
		}
		
		//window.curWin.saveWin();
	}
	
	function removeSelection${field.id}(trId){
		var id = trId.substring('${field.id}_'.length, trId.length);
		var selectedIds = $('#selectedIds_${field.id}').val();
		if (selectedIds.indexOf(id) != -1){
			selectedIds = selectedIds.replace(id+',', '');
			$('#selectedIds_${field.id}').val(selectedIds);
		}
		
		$('#'+trId).remove();
	}
	</script>
	</#if>
	</td>
</tr>
